﻿Option Infer On
Imports Core
Imports Feed.Base
Imports Feed.Storage
Namespace Rendering
    ''TODO: Implement support for multiple templates
    Public Class FeedItems
        Public Shared Function RenderSingleItem(ByVal itm As FeedItem, ByVal template As String) As String
            Dim B As String
            B = My.Computer.FileSystem.ReadAllText(API.ReturnTemplatePath() & "Bluepearl\bluepearl.htm")
            B = B.Replace("{{#ITEMTITLE#}}", itm.Title)
            B = B.Replace("{{#CONTENT#}}", itm.Content)
            B = B.Replace("{{#PATH#}}", API.ReturnTemplatePath() & template & "/")
            B = B.Replace("{{#IMAGEPATH#}}", API.ReturnTemplatePath() & template & "/images")
            B = B.Replace("{{#RETURNTOSUBS#}}", "fm://feeds/list")
            Return B
        End Function
        Public Shared Function RenderMultipleItems(ByVal guid As String, ByVal template As String) As String
            If guid.Contains("res://") Then Exit Function
            If template = "" Then Throw New ArgumentNullException("template")
            Dim itmstorender = New Generic.List(Of FeedItem)
            Dim B As String
            B = My.Computer.FileSystem.ReadAllText(API.ReturnTemplatePath() & "Bluepearl\bluepearl-np.htm")
            Dim maxitems As Integer = 5
            For Each item As FeedItem In [Global].Items
                If item.Guid = guid Then
                    itmstorender.Add(item)
                End If
            Next
            If itmstorender.Count = 0 Then Return "<b>No Items Found</b>"
            B = B.Replace("{{#PATH#}}", API.ReturnTemplatePath() & template & "/")
            B = B.Replace("{{#IMAGEPATH#}}", API.ReturnTemplatePath() & template & "/images")
            B = B.Replace("{{#RETURNTOSUBS#}}", "fm://feeds/list")
            B = B.Replace("\", "/")
            B = B.Replace("{{#FEEDTITLE#}}", itmstorender(0).FeedName)
            For maxitems = 1 To maxitems
                B = B.Replace("{{#IT" & maxitems & "#}}", itmstorender.Item(maxitems).Title)
            Next
            Return B '"<b>Not Implemented</b>"
        End Function
    End Class
End Namespace
